﻿package lobby
{
	import flash.display.MovieClip;
	import flash.events.TimerEvent;
	import flash.text.TextField;
	import flash.utils.Timer;
	
	/**
	 * ...
	 * @author Nguyen Thi Bich Phuong (Daisy)
	 */
	public class WelcomeMessagePanel extends MovieClip
	{
		public var txtMsgTf:TextField;
		public var timer:Timer;
		public var strBlank:String;
		
		public var maxMsg:Number = 200;
		
		public function WelcomeMessagePanel()
		{
			this.timer = new Timer(300);
			this.timer.addEventListener(TimerEvent.TIMER, timerHandler);
			this.strBlank = "          ";
		}
		
		public function startWelcome(strMsg:String)
		{
			trace("startWelcome:" + strMsg);
			this.txtMsgTf.text = strMsg;
			if (this.txtMsgTf.length > 0)
			{
				this.txtMsgTf.appendText(this.strBlank);
				while (this.txtMsgTf.text.length < this.maxMsg)
				{
					this.txtMsgTf.appendText(strMsg + this.strBlank);
				}
				this.timer.start();
			}
		}
		
		private function timerHandler(e:TimerEvent):void
		{
			scrollMessage();
		}
		
		private function scrollMessage():void
		{
			var tmp:String = this.txtMsgTf.text.substr(0, 1);
			this.txtMsgTf.text = this.txtMsgTf.text.substr(1, this.txtMsgTf.text.length - 1) + tmp;
		}
	}

}